﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace AttrapeMoi
{
    public enum Contenu
    {
        vide,
        voleur,
        gendarme,
        inexistant
    }

    class Casee : Sprite
    {
        private Contenu contenu;
        private int numCase;
        private Texture2D tex_gendarme;
        private Texture2D tex_voleur;
        private Texture2D tex_vide;

        public Contenu Contenu1
        {
            get { return contenu; }
            set { contenu = value;
                switch (value)
                {
                    case Contenu.vide:
                        texture = tex_vide;
                        break;

                    case Contenu.gendarme:
                        texture = tex_gendarme;
                        break;

                    case Contenu.voleur:
                        texture = tex_voleur;
                        break;

                }
            }
        }

        public int NumCase
        {
            get { return numCase; }
        }

        public int get_numCase(int longueur_x)
        {
            return (int)position.X + (int)position.Y * longueur_x;
        }

        public Casee()
        {
        }

        public virtual void Initialize(int x, int y, int numero_Case)
        {
            contenu = Contenu.vide;
            numCase = numero_Case;
            position = new Vector2(x, y);
            direction = Vector2.Zero;
            rotation = 0;
            speed = 0;
        }

        public override void LoadContent(ContentManager content)
        {
            tex_vide = content.Load<Texture2D>("vide");
            tex_gendarme = content.Load<Texture2D>("gendarme");
            tex_voleur = content.Load<Texture2D>("voleur");
            texture = tex_vide;
        }

        public virtual void Draw(SpriteBatch spriteBatch, String type_map)
        {
            switch (type_map)
            {
                case "classique":
                case "tore":
                    this.Draw(spriteBatch);
                    break;

                case "hypercube 3":
                    this.DrawHypercube(spriteBatch, 3);
                    break;

                case "hypercube 4":
                    this.DrawHypercube(spriteBatch, 4);
                    break;
            }
        }

        public virtual void DrawHypercube(SpriteBatch spriteBatch, int nbHypercube)
        {
            Vector2 positionReel = new Vector2();
            if (nbHypercube == 4)
            {
                switch (numCase)
                {
                    case 0:
                        positionReel = new Vector2(4 * 20, 0);
                        break;

                    case 1:
                        positionReel = new Vector2(7 * 20, 20);
                        break;

                    case 2:
                        positionReel = new Vector2(8 * 20, 4 * 20);
                        break;

                    case 3:
                        positionReel = new Vector2(7 * 20, 7 * 20);
                        break;

                    case 4:
                        positionReel = new Vector2(4 * 20, 8 * 20);
                        break;

                    case 5:
                        positionReel = new Vector2(20, 7 * 20);
                        break;

                    case 6:
                        positionReel = new Vector2(0, 4 * 20);
                        break;

                    case 7:
                        positionReel = new Vector2(20, 20);
                        break;

                    case 8:
                        positionReel = new Vector2(4 * 20, 2 * 20);
                        break;

                    case 9:
                        positionReel = new Vector2(5 * 20, 3 * 20);
                        break;

                    case 10:
                        positionReel = new Vector2(6 * 20, 4 * 20);
                        break;

                    case 11:
                        positionReel = new Vector2(5 * 20, 5 * 20);
                        break;

                    case 12:
                        positionReel = new Vector2(4 * 20, 6 * 20);
                        break;

                    case 13:
                        positionReel = new Vector2(3 * 20, 5 * 20);
                        break;

                    case 14:
                        positionReel = new Vector2(2 * 20, 4 * 20);
                        break;

                    case 15:
                        positionReel = new Vector2(3 * 20, 3 * 20);
                        break;
                }
            }
            else
            {
                switch (numCase)
                {
                    case 0:
                        positionReel = new Vector2(2 * 20, 2 * 20);
                        break;

                    case 1:
                        positionReel = new Vector2(4 * 20, 2 * 20);
                        break;

                    case 2:
                        positionReel = new Vector2(2 * 20, 4 * 20);
                        break;

                    case 3:
                        positionReel = new Vector2(4 * 20, 4 * 20);
                        break;

                    case 4:
                        positionReel = new Vector2(0, 0);
                        break;

                    case 5:
                        positionReel = new Vector2(6 * 20, 0);
                        break;

                    case 6:
                        positionReel = new Vector2(0, 6 * 20);
                        break;

                    case 7:
                        positionReel = new Vector2(6 * 20, 6 * 20);
                        break;
                }
            }
            spriteBatch.Draw(texture, positionReel, Color.White);

        }

        public virtual void DrawSpecialTexture(Texture2D temp_text, String type_map, SpriteBatch spriteBatch)
        {
            Texture2D tex_temp = texture;
            texture = temp_text;

            this.Draw(spriteBatch, type_map);

            texture = tex_temp;
        }
    }
}
